<template>
    <div style="margin: 10px 10px">
      <div style="margin-bottom: 10px">
        <el-input v-model="recName" style="width: 150px;margin-right: 5px" placeholder="请输入学生姓名" ></el-input>
        <el-button type="primary" @click="searchName">搜索</el-button>
      </div>
      <div>
        <el-table
          :data="plans"
          border
          style="width: 100%">
          <el-table-column
            prop="recruitStuName"
            label="招生学生姓名"
            align="center"
            width="400">
          </el-table-column>
          <el-table-column
            prop="planData"
            label="日期"
            align="center"
            width="400">
          </el-table-column>
          <el-table-column
            prop="planTarget"
            label="招生目标"
            align="center"
            width="405">
          </el-table-column>
          <el-table-column
            label="操作"
            align="center"
            width="100">
            <template slot-scope="scope">
              <el-button @click="handleClick(scope.row)" type="text" size="small">查看详情</el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-dialog
          title="详情"
          :visible.sync="dialogVisible"
          width="30%">
          <el-form v-model="plan" label-width="100px">
            <el-form-item label="招生学生姓名">
              {{plan.recruitStuName}}
            </el-form-item>
            <el-form-item label="招生日期">
              {{plan.planData}}
            </el-form-item>
            <el-form-item label="招生目标">
              {{plan.planTarget}}
            </el-form-item>
            <el-form-item label="招生计划">
              {{plan.planDetail}}
            </el-form-item>
          </el-form>
          <span slot="footer" class="dialog-footer">
            <el-button @click="dialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
          </span>
        </el-dialog>
        <el-pagination
          style="margin-top: 10px"
          @current-change="currentChange"
          :current-page="currentPage"
          background
          layout="prev, pager, next"
          :total="total">
        </el-pagination>
      </div>
    </div>
</template>

<script>
import { initPlan, getByName } from '../../../api/tea/plan'

export default {
  data() {
    return {
      recName: '',
      currentPage: 1,
      total: 100,
      dialogVisible: false,
      plans: [{
        recruitStuName: '',
        planData: '2021-06-02',
        planTarget: '2',
        planDetail: ''
      }],
      plan: {
        recruitStuName: '',
        planData: '2021-06-02',
        planTarget: '2',
        planDetail: ''
      }
    }
  },
  methods: {
    // 查看详情
    handleClick(row) {
      console.log(row)
      this.plan = row
      this.dialogVisible = true
    },
    // 当前页数据
    currentChange(page) {
      this.currentPage = page
      initPlan(this.currentPage).then(response=>{
        console.log(response)
        if (response.data == null){
          this.plans = []
          this.total = 10
        } else {
          this.plans = response.data.records
          this.total = response.data.total
        }
      })
    },
    // 搜索
    searchName() {
      if (this.recName === ''){
        this.currentChange(this.currentPage)
      } else {
        getByName(this.recName,1).then(response=>{
          console.log(response)
          this.plans = response.data.records
          this.total = response.data.total
        })
      }
    }
  },
  created() {
    this.currentChange(1)
  }
}
</script>

<style scoped>

</style>
